
let path=require('path');                    
let fs=require('fs');                    
let url=require('url');                    
let http=require('http');                    

http.createServer((req,res)=>{
    // console.log(req.url);//请求路径
    let {pathname}=url.parse(req.url,true);
    pathname=pathname==='/'?'index.html':pathname;
    console.log(pathname);

    if(path.extname(pathname)&&path.extname(pathname)!=='.ico'){
        res.end(fs.readFileSync(path.join('./public', pathname),'utf-8'))
    }
    
}).listen(9000, () => {
    console.log(`服务器启动成功,http://localhost:9000`)
})